<!DOCTYPE html>
<!--[if IE 8]> <html lang="en" class="ie8 no-js"> <![endif]-->
<!--[if IE 9]> <html lang="en" class="ie9 no-js"> <![endif]-->
<!--[if !IE]><!-->
<html lang="en" class="no-js">
<!--<![endif]-->
<!-- BEGIN HEAD -->
<head>
<meta charset="utf-8" />
<title>订单管理 - 订单列表</title>
<?php include($this->c['_homes']['_viewsHome'].'/_global/_head.php');?>
<link rel="stylesheet" type="text/css" href="/style/assets/plugins/bootstrap-datetimepicker/css/datetimepicker.css" />
</head>
<!-- BEGIN BODY -->
<body class="page-header-fixed page-sidebar-fixed">
<!-- BEGIN HEADER -->
<?php include($this->c['_homes']['_viewsHome'].'/_global/head.php');?>
<!-- END HEADER -->
<div class="clearfix"></div>
<!-- BEGIN CONTAINER -->
<div class="page-container" > 
  <!-- BEGIN HORIZONTAL MENU PAGE SIDEBAR1 -->
  <?php include($this->c['_homes']['_viewsHome'].'/_global/menu.php');?>
  <!-- END BEGIN HORIZONTAL MENU PAGE SIDEBAR --> 
  <!-- BEGIN PAGE -->
  <div class="page-content"> 
    <!-- BEGIN PAGE HEADER-->
    <div class="row">
      <div class="col-md-12"> 
        <!-- BEGIN PAGE TITLE & BREADCRUMB-->
        <h3 class="page-title"> 订单列表 </h3>
        <ul class="page-breadcrumb breadcrumb">      
          <?php if($this->pv['export'] || $this->pv['import']){?>  	
          <li class="btn-group">
            <button type="button" class="btn blue dropdown-toggle" data-toggle="dropdown" data-hover="dropdown" data-delay="1000" data-close-others="true"> <span>操作</span> <i class="icon-angle-down"></i> </button>
            <ul class="dropdown-menu pull-right" role="menu">
              <?php if($this->pv['export']){?>
             
              <li><a href="/order/export"> <i class="icon-download-alt"></i>导出未发货订单</a></li>
              <li><a href="/order/export?type=1"> <i class="icon-download-alt"></i>导出已发货订单</a></li>
              <?php } ?>
              <?php if($this->pv['import']){ ?>
              <li><a href="/order/import"> <i class="icon-upload-alt"></i>导入物流</a></li>
              <?php } ?>

              
            </ul>
          </li>
          <?
          }
          ?>
          <li> <i class="icon-home"></i> <a href="/manage">后台</a> <i class="icon-angle-right"></i> </li>
          <li> 订单管理 <i class="icon-angle-right"></i> </li>
          <li>订单列表</li>
        </ul>
        <!-- END PAGE TITLE & BREADCRUMB--> 
      </div>
    </div>
    <!-- END PAGE HEADER--> 
    <!-- BEGIN PAGE CONTENT-->
    <div class="row">
      <div class="col-md-12">
        <div class="portlet box">
          <div class="booking-search">
            <form action="" role="form" method="get" id="forms">
              <div class="row form-group">              
                <div class="col-md-3">
                  <div class="input-cont">
                    <input class="form-control" name="keyword" placeholder="收货人姓名/订单号/订单ID" value="<?=$_GET['keyword'];?>" type="text">
                  </div>
                </div>
                  <div class="col-md-2">
                      <div class="input-cont">
                          <input class="form-control" name="recode" placeholder="购买人邀请码" value="<?=$_GET['recode'];?>" type="text">
                      </div>
                  </div>
                 <div class="col-md-3">
                    <div class="input-group date form_datetime" data-date="<?=date("Y-m-d\TH:i\Z");?>">
                            <input type="text" size="16" name="start_time" placeholder="选择开始时间" id="start_time" value="<?=$_GET['start_time']?>" readonly class="form-control">
                            <span class="input-group-btn">
                            <button class="btn default date-reset" type="button"><i class="icon-remove"></i></button>
                            </span> <span class="input-group-btn">
                            <button class="btn default date-set" type="button"><i class="icon-calendar"></i></button>
                            </span> </div>
                  </div>
                  <div class="col-md-3">
                    <div class="input-group date form_datetime" data-date="<?=date("Y-m-d\TH:i\Z");?>">
                            <input type="text" size="16" name="end_time" placeholder="选择结束时间" id="end_time" value="<?=$_GET['end_time']?>" readonly class="form-control">
                            <span class="input-group-btn">
                            <button class="btn default date-reset" type="button"><i class="icon-remove"></i></button>
                            </span> <span class="input-group-btn">
                            <button class="btn default date-set" type="button"><i class="icon-calendar"></i></button>
                            </span> </div>
                  </div> 
               </div>  
               <div class="row form-group">   
                <div class="col-md-2">                  
                  <div class="input-cont">
                    <input class="form-control" name="gkwd" placeholder="商品名称/商品ID" value="<?=$_GET['gkwd'];?>" type="text">
                  </div>
                </div>             
                <div class="col-md-2">                  
                  <select class="form-control" name="pay_status">
                    <option value="">付款状态</option>
                    <?php
          					if($this->c['stat']['order_show']['pay']){
          						foreach($this->c['stat']['order_show']['pay'] as $k=> $r){
          							if(isset($this->data['para']['pay_status']) && $k==$this->data['para']['pay_status']) $slk = ' selected';
          							else $slk = '';
          							?>
                        <option value="<?=$k;?>"<?=$slk;?>><?=$r;?></option>
                    <?
          						}
          					}
          					?>
                 </select>
                </div>
                
               
                <div class="col-md-2">                  
                  <select class="form-control" name="shipping_status">
                    <option value="">发货状态</option>
                    <?php
                    if($this->c['stat']['order_show']['shipping']){
                      foreach($this->c['stat']['order_show']['shipping'] as $k=> $r){
                        if(isset($this->data['para']['shipping_status']) && $k==$this->data['para']['shipping_status']) $slk = ' selected';
                        else $slk = '';
                        ?>
                        <option value="<?=$k;?>"<?=$slk;?>><?=$r;?></option>
                        
                    <?
                        
                      }
                    }
                    ?>
                 </select>
                </div>
               </div>
                <div class="row form-group">
                <div class="col-md-2">
                       <select class="form-control" name="province_id" onchange="changeProvince(this,'city_id')">
                           <option value="">==省==</option>
                           <?php foreach ($this->province as $region_id => $region_name) {?>
                               <option value="<?=$region_id?>" <?php if ($region_id == $this->data['para']['province_id']): ?>selected="selected"<?php endif;?>><?=$region_name?></option>
                           <?php }?>
                       </select>
                   </div>
                   <div class="col-md-2">
                       <select class="form-control" name="city_id" onchange="changeProvince(this,'county_id')" id="city_id">
                           <option value="">==市==</option>
                           <?php
                           if($this->city_list){
                           foreach ($this->city_list as $region_id => $region_name) {?>
                               <option value="<?=$region_id?>" <?php if ($region_id == $this->data['para']['city_id']): ?>selected="selected"<?php endif;?>><?=$region_name?></option>
                           <?php }}?>
                       </select>
                   </div>
                   <div class="col-md-2">
                       <select class="form-control" name="county_id" id="county_id">
                           <option value="">==区/县==</option>
                           <?php
                           if($this->county_list){
                           foreach ($this->county_list as $region_id => $region_name) {?>
                               <option value="<?=$region_id?>" <?php if ($region_id == $this->data['para']['county_id']): ?>selected="selected"<?php endif;?>><?=$region_name?></option>
                           <?php }}?>
                       </select>
                   </div>


                       <div class="col-md-1"><input type="submit" class="btn blue btn-block" value="搜 索"></div>
                       <div class="col-md-2"><input type="button" class="btn green btn-block" value="统计" onclick="_order_money_count();"></div>
                    <?php if($this->pv['export']){?>
                       <div class="col-md-2"><input type="button" class="btn green btn-block" value="导出" onclick="_order_all_export();"></div>
                    <?php }?>
                    <div class="col-md-2" style="display:none;" id="order_money_count"></div>
                </div>
            </form>
          </div>
        </div>
      </div>
    </div>
    <div class="row">
      <div class="col-md-12"> 
        <!-- BEGIN SAMPLE TABLE PORTLET-->                  
        <div class="portlet box blue">
          <div class="portlet-title">
            <div class="caption"><i class="icon-list"></i>列表(<?=$this->data['count'];?>)</div>                      
		      <div class="actions">
              <div class="btn-group"> <a class="btn red" href="#" data-toggle="dropdown"> <i class="icon-cog"></i> 批量操作 <i class="icon-angle-down"></i> </a>
                <ul class="dropdown-menu pull-right">
                  <li><a href="javascript:;"  onclick="_shipping()"><i class="i"></i> 设置发货中</a></li>                  
                </ul>
              </div>
            </div>
          </div>    
          <div class="portlet-body">
            <div class="table-scrollable">
             <table class="table table-striped table-bordered table-hover dataTable">
              <thead>
                <tr>
                 <th><input type="checkbox" id="_checkboxall" value="1"></th>
                    <th>订单编号</th>
                    <th>下单时间</th>
                    <th>买家昵称</th>
                    <th>会员级别</th>
                    <th>会员邀请码</th>
                    <th>会员姓名</th>
                    <th>抵用金花</th>
                    <th>抵用代金券</th>
                    <th>抵用优惠券</th>
                    <th>收货人</th>
                    <th>支付金额</th>
                    <th>订单状态</th>
                    <th>操作</th>
                </tr>
              </thead>
             <tbody>
              <?php
            			if($this->data['data'])
            			{
            				foreach($this->data['data'] as $k=> $r){										
            					
            					if($this->data['user'][$r['uid']]['headimgurl']!=""){
            						
            						 $headimg = str_replace("/0","/64",$this->data['user'][$r['uid']]['headimgurl']);	
            						
            					}
            					else $headimg = '/style/assets/img/avatar.png';

            			?>
                <tr>
                  <td><input type="checkbox" class="_checkboxs" name="order_id[]" value="<?=$r['order_id'];?>"></td>
                  <td onclick="checkShow(<?=$r['order_id'];?>)" style="cursor:pointer;"><?=$r['order_sn'];?></td>
                  <td><?=date("Y-m-d H:i",$r['add_time']);?></td>
                  <td>[<?=$r['uid'];?></a>] <?=stripslashes($this->data['user'][$r['uid']]['realname']);?></a> </td>
                  <td><?=$this->c['member_level'][$this->data['user'][$r['uid']]['member_level']];?></td>
                  <td> <?=stripslashes($this->data['user'][$r['uid']]['recode']);?></td>
                  <td> <?=stripslashes($this->data['user'][$r['uid']]['name']);?></td>
                  <td><?=$r['gold_fee'];?></td>
                  <td><?=$r['coupon_fee'];?></td>
                  <td><?=$r['discount_fee'];?></td>
                  <td><?=$r['consignee'];?></td>
                  <td><?=$r['pay_fee'];?></td>
                  <td>
                  <?=$this->c['stat']['order_show']['status'][$r['order_status']];?>
                  <?=$this->c['stat']['order_show']['shipping'][$r['shipping_status']];?>
                  <?=$this->c['stat']['order_show']['pay'][$r['pay_status']];?>
                  </td>
                  <td><?php
        				  if($this->pv['view']) echo '<a href="detail?order_id='.$r['order_id'].'" class="btn btn-xs blue"><i class="icon-eye-open"></i> 查看</a>';
        				  if($this->pv['ex']) echo ' <a href="export?order_id='.$r['order_id'].'"  class="btn btn-xs blue"><i class="icon-edit"></i> 导出</a>';
        				  //if($this->pv['print']) echo ' <a href="orderprint?order_id='.$r['order_id'].'"  class="btn btn-xs blue"><i class="icon-edit"></i>打印</a>';                  
        				  ?>
                      <a href="javascript:checkShow(<?=$r['order_id'];?>)" class="btn btn-xs blue"><i class="icon-eye-open"></i> 商品</a>
                            </td>
                        </tr>
                        <?
        					}
        				}
        				?>

				 </tbody>                                
            </table>
            </div>
          </div>
        </div>
        <?php
		if($this->data['maxpage'] > 1){
		?>
        <div>
          <ul class="pagination">
            <?
			$pquery="?";		
			if($this->data['para']){			
				foreach($this->data['para'] as $k=>$r){				
					$pquery.=$k."=".$r."&";
					$form_hidden .= '<input type="hidden" name="'.$k.'" value="'.$r.'">';
				}			
			}
			
			if($this->data['page'] > 1) echo '<li><a href="'.$pquery.'page='.($this->data['page']-1).'"><i class="icon-angle-left"></i></a></li>';
			for($i = $this->data['spage']['ps']; $i<=$this->data['spage']['pe']; $i++){
			if($i == $this->data['page']) echo '<li class="disabled"><a href="javascript:void(0);">'.$i.'</a></li>';
			else echo '<li><a href="'.$pquery.'page='.$i.'">'.$i.'</a></li>';
			}
			
			if($this->data['page'] < $this->data['maxpage']) echo '<li><a href="'.$pquery.'page='.($this->data['page']+1).'"><i class="icon-angle-right"></i></a></li>';
			?>
          </ul>
          <div class="jumppage">
          <form method="get" action="">
          <?=$form_hidden;?>
          页码：<?=$this->data['page'];?>/<?=$this->data['maxpage'];?>
          跳到 <input type="text" name="page" class="value"> 页          
          <input type="submit" value="GO" class="sub">
          </form>
          </div>
        </div>
        <?
 		}
?>
        <!-- END SAMPLE TABLE PORTLET--> 
      </div>
    </div>
    <!-- END PAGE CONTENT--> 
  </div>
  <!-- END PAGE --> 
</div>
<!-- END CONTAINER -->
<form method="post" id="_batch" action="/order/exportBatchs">
  <input type="hidden" name="order_ids" id="_batch_dataid" value="">
</form>
<?php include($this->c['_homes']['_viewsHome'].'/_global/_footer.php');?>
<script type="text/javascript" src="/style/assets/plugins/bootstrap-datetimepicker/js/bootstrap-datetimepicker.js"></script> 
<script type="text/javascript" src="/style/assets/plugins/bootstrap-datetimepicker/js/locales/bootstrap-datetimepicker.zh-CN.js"></script>
<script type="text/javascript" src="/style/js/layer/layer.min.js"></script>
<script>
jQuery(document).ready(function() {    
   App.init();
   handleDatetimePicker();
   if (jQuery().datepicker) {
       $('.date-picker').datepicker({
           rtl: App.isRTL(),
           autoclose: true
       });
       $('body').removeClass("modal-open"); // fix bug when inline picker is used in modal
     }
   jQuery('#_checkboxall').change(function () {
	  var checked = jQuery(this).is(":checked");
	  jQuery("._checkboxs").each(function () {
		  if (checked) {
			  $(this).attr("checked", true);
		  } else {
			  $(this).attr("checked", false);
		  }
		  $(this).parents('tr').toggleClass("active");
	  });
	  jQuery.uniform.update("._checkboxs");
  });
  
  $("._checkboxs").change(function() {
	  var checked = jQuery(this).is(":checked");
	  if (!checked) {			
		  $(this).attr("checked", false);
		  $(this).parents('tr').removeClass("active");
		  $("#_checkboxall").attr("checked",false);
		  jQuery.uniform.update("#_checkboxall");
	  }
  });
});

var handleDatetimePicker = function () {
	  $(".form_datetime").datetimepicker({
	    language:'zh-CN',
	    autoclose: true,
	    format: "yyyy-mm-dd hh:ii"
	  }); 
	  $('body').removeClass("modal-open"); // fix bug when inline picker is used in modal
	}
function _export_action(){
	$("#_dataid").prop("value",_dataid);
	$("#_frm").submit();
}

function _batch(){
	var _ids = '';
	
	$("._checkboxs").each(function () {
		if( $(this).attr("checked")  ) {
			if(_ids!="") _ids +=',';
			_ids += $(this).val();
		}
	});
	if(_ids!=""){
		$("#_batch_dataid").prop("value",_ids);
		cm = confirm("您确定要导出这些订单吗？");
		if(cm){
				$("#_batch").submit();
		}
	}
	else alert("至少选择一个订单");
}

function _shipping(){
	var _idss = '';
	
	$("._checkboxs").each(function () {
		if( $(this).attr("checked")  ) {
			if(_idss!="") _idss +=',';
			_idss += $(this).val();
		}
	});
	if(_idss!=""){
		//$("#_orderIds").prop("value",_idss);
		cm = confirm("您确定要设置这些订单为发货中吗？");
		if(cm){
			
			$.post("ajax",
	  	      {
	  	        "act":"shipping_status",
	  	        "order_ids":_idss,
	  	        "mr":Math.random()
	  	      },
	  	      function(json){
	  	        if(json.code==200)
	  	        {
	  	          swal("保存成功",false,"success");
		  	        window.location.reload();    

	  	        }
	  	        else{
	  	          swal(json.msg,"错误代码["+json.code+"]","error");
	  	        }

	  	      },"json"); 
		}
	}
	else alert("至少选择一个订单");
}

//获取指定省下的所有市
function changeProvince(obj,pid){
    var id = $(obj).val();
    var data = {
        'act':'getCiys',
        'id':id,
    }

    // console.log(province_id);
    $.ajax({
        url:'/order/ajax',
        type:'post',
        data:data,
        dataType:'json',
        success:function(data){
            var htmls = '<option value="">==区/县==</option>';
            if(pid=="city_id"){
                $("#county_id").html(htmls);
                var htmls = '<option value="">==市==</option>';


            }

           // alert(JSON.stringify(data))
            if(data != '' && data !=null){


                $.each(data,function(index,value){

                    htmls += "<option value="+ index +">"+value+"</option>";
                })

                //alert(JSON.stringify(htmls))
                $('#'+pid).html(htmls);
            }else{

                $('#'+pid).html(htmls);
            }


        },
        error:function(res){
            console.log(res)
        }
    })
}

function _order_money_count()
{
    $.ajax({
        url:'/order/order_money_count',
        type:'get',
        data: $("#forms").serialize() + "&mr=" + Math.random(),
        dataType:'json',
        success:function(data){
            $('#order_money_count').show();
            $('#order_money_count').html("订单总额："+data);

        },
        error:function(res){
            console.log(res)
        }
    })


}

function _order_all_export()
{
    var obj = $('#forms').serialize();
    window.open("exportAllBatch?"+obj);

}

function checkShow(order_id) {
    check_open_index = layer.open({
        type: 2,
        title: '订单商品信息',
        shadeClose: true,
        shade: 0.6,
        area: ['100%', '40%'],
        content: ['/order/order_goods_detail?order_id=' + order_id],
    });
}
</script> 
<!-- END JAVASCRIPTS -->
</body>
<!-- END BODY -->
</html>